package eu.telecom_bretagne.CESI.servlet;

import java.io.IOException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import eu.telecom_bretagne.CESI.service.IGestionDemande;

/**
 * Servlet implementation class LireListeImprimeur
 */
@WebServlet("/realiser_demandes")
public class LireListeARealiserImprimeur extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LireListeARealiserImprimeur() {
        super();
        // TODO Auto-generated constructor stub
    }

	
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
String[] realisation_ids=request.getParameterValues("liste_realisations");
		
		if(realisation_ids==null){
			response.sendRedirect("index.jsp");
			return;	
		}
		
		try {
			InitialContext ctx= new InitialContext();
			IGestionDemande gestionDemande= 
					(IGestionDemande)ctx.lookup(IGestionDemande.JNDI_NAME);
			for (String id:realisation_ids)
				gestionDemande.realiserImpression(Integer.parseInt(id));
			} catch (NamingException e) {
			// TODO: handle exception
			throw new ServletException(e);
		}
		response.sendRedirect("index.jsp");
	}

}
